package com.ust.app.movie.service.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.ust.app.movie.entity.User;
import com.ust.app.movie.service.LoginDao;

public class LoginDaoImpl implements LoginDao{

	HibernateTemplate hibernateTemplate;
	
	public LoginDaoImpl(HibernateTemplate hibernateTemplate){
		this.hibernateTemplate = hibernateTemplate;
	}
	
	public User getUser(User user) {
		
		String[] userParms = {user.getUsername(), user.getPassword()};
		
		List<User> users =  hibernateTemplate.find("from User u where u.username=? and u.password=?", userParms);
		
		if(users.size() > 1 || users.size() == 0){
			return user;
		}
		
		return users.get(0);
	}

}
